package messageHandler;

import network.Cmd_Message;
import network.Message;
import screen.FightingScr;

public class GameFightingMsgHandler extends GameCenterMsgHandler{
	static GameFightingMsgHandler m_instance = null;
	
    public static GameFightingMsgHandler gI() {
        if (m_instance == null) {
            m_instance = new GameFightingMsgHandler();
        }
        return m_instance;
    }
	
	public static void onHandler() {		
		GlobalMsgHandler.gI().miniGameMessageHandler = GameFightingMsgHandler.gI();			
	}
	public void onMessage(Message msg) {
		// TODO Auto-generated method stub
		try {
            switch (msg.command) {
            case Cmd_Message.START:
            	short roomID = msg.reader().readByte();
            	short boardID = msg.reader().readByte();
            	short interval = msg.reader().readByte();
            	int whoPlay = msg.reader().readInt();
            	short health0 = msg.reader().readShort();
            	short health1 = msg.reader().readShort();
            	FightingScr.gI().onStartGame(whoPlay, interval, health0, health1);
            	break;
            	
            case Cmd_Message.SHOOT://message do xuc xac
            	roomID = msg.reader().readByte();
            	boardID = msg.reader().readByte();
            	whoPlay = msg.reader().readInt();//nguoi do xuc xac
            	byte point = msg.reader().readByte();//diem so do duoc
            	int nextPlay = msg.reader().readInt();//nguoi choi tiep theo
            	boolean isNewPlay = msg.reader().readBoolean();//bat dau luot choi moi hay khong
            	int whoAttack = msg.reader().readInt();//nguoi gianh quyen tan cong
            	FightingScr.gI().onThrowDice(whoPlay, point, nextPlay, isNewPlay, whoAttack);
            	break;
            
            case Cmd_Message.END_GAME:
            	roomID = msg.reader().readByte();
            	boardID = msg.reader().readByte();
            	int whoWin = msg.reader().readInt();
            	boolean howOutGame = msg.reader().readBoolean();
            	FightingScr.gI().onEndGame(whoWin, howOutGame);
            	break;
            	           	
            default:
            	super.onMessage(msg);
            	break;
            }
		}catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	}
}
